<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter;

class OrderGoods extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $exists = $this->hasTable('order_goods');
        if(!$exists){
        $table = $this->table('order_goods', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_unicode_ci', 'comment' => '订单商品' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
        $table->addColumn('order_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => null,'signed' => true,'comment' => '订单ID',])
			->addColumn('goods_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => null,'signed' => true,'comment' => '商品ID',])
			->addColumn('goods_product_id', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => false,'default' => null,'signed' => true,'comment' => '商品规格ID',])
			->addColumn('goods_name', 'string', ['limit' => 50,'null' => false,'default' => null,'signed' => true,'comment' => '商品名称',])
			->addColumn('product_price', 'decimal', ['precision' => 10,'scale' => 2,'null' => false,'default' => 0,'signed' => true,'comment' => '价格',])
			->addColumn('product_line_price', 'decimal', ['precision' => 10,'scale' => 2,'null' => false,'default' => 0,'signed' => true,'comment' => '划线价格',])
			->addColumn('product_img', 'string', ['limit' => 255,'null' => false,'default' => null,'signed' => true,'comment' => '规格图片',])
			->addColumn('product_name', 'string', ['limit' => 50,'null' => false,'default' => null,'signed' => true,'comment' => '规格名称',])
			->addColumn('quantity', 'string', ['limit' => 11,'null' => false,'default' => 0,'signed' => true,'comment' => '数量',])
			->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '状态：0 售后中、1 正常、2 已退款',])
			->addColumn('create_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '创建时间',])
			->addColumn('update_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '更新时间',])
            ->create();
        }
    }
}
